package com.zhongke.cotrun.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhongke.cotrun.mapper.NeedInfoMapper;
import com.zhongke.cotrun.mapper.WxSysDictMapper;
import com.zhongke.cotrun.model.pojo.NeedInfo;
import com.zhongke.cotrun.service.NeedInfoService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NeedInfoServiceImpl implements NeedInfoService {

    @Autowired
    NeedInfoMapper needInfoMapper;
    @Autowired
    WxSysDictMapper wxSysDictMapper;
    /**
     * 根据id查看需求详情
     *
     * @param 需求表主键
     * @return
     */
    public NeedInfo selectDetailById(Long id){
    	return needInfoMapper.selectDetailById(id);
    }
    /**
     * 根据用户id查看用户需求列表
     * @param userId 用户表主键
     * @param searchKey 关键词
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return
     */
	public PageInfo selectAllByMine(Long userId,String searchKey, Integer pageNum, Integer pageSize){
		PageHelper.startPage(pageNum, pageSize);
		List<NeedInfo> list = needInfoMapper.selectAllByMine(userId,searchKey);
		PageInfo pageInfo = new PageInfo(list);
	    return pageInfo;
	}
	/**
     * 前端检索用户需求信息
     * @param type 需求类型
     * @param technicalFieldId 技术领域主键
     * @param province 省主键
     * @param city 市主键
     * @param searchKey 检索关键词
     * @param sort 排序，无或空，默认降，'up'为升，'down'为降
     * @param pageNum页码
     * @param pageSize页大小
     * @return
     */
    public PageInfo selectAll(String type, String technicalFieldId,String province,String city,String searchKey,String sort, Integer pageNum, Integer pageSize){
    	PageHelper.startPage(pageNum, pageSize);
		List<NeedInfo> list = needInfoMapper.selectAll(type, technicalFieldId, province, city, searchKey,sort);
		PageInfo pageInfo = new PageInfo(list);
	    return pageInfo;
    }
    /**
     * 管理后台检索用户需求信息
     * @param type 需求类型
     * @param technicalFieldId 技术领域主键
     * @param province 省主键
     * @param city 市主键
     * @param searchKey 检索关键词
     * @param state 状态
     * @param endDateS 截止时间（始）
     * @param endDateE 截止时间（止）
     * @param pageNum页码
     * @param pageSize页大小
     * @return
     */
    public PageInfo selectAllByManager(String type, String technicalFieldId,String province,String city,String searchKey,String state, String endDateS,String endDateE,Integer pageNum, Integer pageSize){
    	PageHelper.startPage(pageNum, pageSize);
    	
		List<NeedInfo> list = needInfoMapper.selectAllByManager(type, technicalFieldId, province, city, searchKey,state,endDateS,endDateE);
		PageInfo pageInfo = new PageInfo(list);
	    return pageInfo;
    }
    /**
     * 按状态统计
     * @param state 状态
     * @return
     */
    public int queryUnApprovalCounts(String state){
    	return needInfoMapper.queryUnApprovalCounts(state);
    }
    /**
     * 新增
     * @param  对象
     * @return
     */
    public boolean add(NeedInfo needInfo) {
        return needInfoMapper.insert(needInfo);
    }
    /**
     * 修改
     * @param 对象
     * @return
     */
    public boolean update(NeedInfo needInfo) {
        return needInfoMapper.update(needInfo);
    }
    /**
     * 系统自动下线
     * @return
     */
    public int cronJobsUpdateState3(){
        return needInfoMapper.cronJobsUpdateState3();
    }
    /**
     * 删除
     * @param id 需求主键
     * @param userInfoId 用户表主键
     * @return
     */
    public boolean delete(Long id,Long userId){
    	return needInfoMapper.deleteByID(id, userId);
    }
    /**
     * 后台删除
     * @param id 需求主键
     * @param userId 更新人
     * @return
     */
    public boolean managerDelete(String id,Long userId){
    	return needInfoMapper.managerDeleteByID(id,userId);
    }
    /**
     * 下线
     * @param id 需求主键
     * @param userInfoId 用户表主键
     * @return
     */
    public boolean offline(Long id,Long userId){
    	return needInfoMapper.offline(id, userId);
    }
    /**
     * 后台下线
     * @param id 需求主键
     * @param userId 更新人
     * @return
     */
    public boolean managerOffline(Long id,Long userId){
    	return needInfoMapper.managerOffline(id,userId);
    }
    /**
     * 后台审核
     * @param id 需求主键
     * @param userId 更新人
     * @param state 需求状态
     * @param remarks 备注
     * @return
     */
    public boolean managerCheck(Long id,Long userId,String state,String remarks){
    	return needInfoMapper.managerCheck(id, userId, state,remarks);
    }
}
